

#if !defined(COCO_PARSER_H__)
#define COCO_PARSER_H__



#include "Scanner.h"
#include "ast.h"
#include "codegen.h"
#include "symtab.h"







class Errors {
public:
	int count;			// number of errors detected

	Errors();
	void SynErr(int line, int col, int n);
	void Error(int line, int col, const wchar_t *s);
	void Warning(int line, int col, const wchar_t *s);
	void Warning(const wchar_t *s);
	void Exception(const wchar_t *s);

}; // Errors

class Parser {
private:
	enum {
		_EOF=0,
		_ident=1,
		_uint=2,
		_binnum=3,
		_hexnum=4,
		_float=5,
		_char=6,
		_string=7,
		_pkg=8,
		_terminate=9,
		_EOL=10
	};
	int maxT;

	Token *dummyToken;
	int errDist;
	int minErrDist;

	void SynErr(int n);
	void Get();
	void Expect(int n);
	bool StartOf(int s);
	void ExpectWeak(int n, int follow);
	bool WeakSeparator(int n, int syFol, int repFol);

public:
	Scanner *scanner;
	Errors  *errors;

	Token *t;			// last recognized token
	Token *la;			// lookahead token

        int StringToInt(const char * s)
        {
                int digit, l, i = 0, num = 0;
                l = strlen(s);
                while( i <= l && isdigit(s[i]) )
                {
                        digit = s[i] - '0'; ++i;
                        num = 10 * num + digit;
                }
                return num;
        }

/*****************[ Scanner Region ] *****************/


	Parser(Scanner *scanner);
	~Parser();
	void SemErr(const wchar_t* msg);

	void EON();
	void ClassDeclaration();
	void StatementSequence();
	void Ident(char *name);
	void Statement();
	void VarDeclaration();
	void Assignment();
	void Directive();
	void BlockStatement();
	void Variable(ASTNode * &V);
	void rhs();
	void Designator(ASTNode * &D, classset allowed, SymTableEntry & entry, bool entire);
	void Expression(ASTNode * &E,bool entire);
	void Number(int &num);
	void String(char * str);
	void IfConditional();
	void WhileConditional();
	void ForeachLoop();
	void Condition(ASTNode * &C);
	void RelOp(opers &op);
	void Term(ASTNode * &T, bool entire);
	void AddSubOp(opers &op);
	void Factor(ASTNode * &F,bool entire);
	void MultDivOp(opers &op);

	void Parse();

}; // end Parser



#endif // !defined(COCO_PARSER_H__)

